home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / asciishopsource / AppClasses.jar / asciiShop / mainFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-06-23  |  8.9 KB  |  329 lines

  1. package asciiShop;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.FileDialog;
  7. import java.awt.Frame;
  8. import java.awt.Insets;
  9. import java.awt.LayoutManager;
  10. import java.awt.List;
  11. import java.awt.Menu;
  12. import java.awt.MenuBar;
  13. import java.awt.MenuItem;
  14. import java.awt.Point;
  15. import java.awt.TextArea;
  16. import java.awt.Window;
  17. import java.awt.event.ActionEvent;
  18. import java.awt.event.ItemEvent;
  19. import java.awt.event.TextEvent;
  20. import java.awt.event.WindowEvent;
  21. import java.io.BufferedReader;
  22. import java.io.FileNotFoundException;
  23. import java.io.FileReader;
  24. import java.io.FileWriter;
  25. import java.io.IOException;
  26. import java.io.PrintWriter;
  27.  
  28. public class mainFrame extends Frame {
  29.    char[][] artBuffer2;
  30.    int useLength;
  31.    int length1;
  32.    int length2;
  33.    int globalCount = 0;
  34.    PrintWriter writeToFile;
  35.    String bigString;
  36.    // $FF: renamed from: i int
  37.    int field_0;
  38.    // $FF: renamed from: j int
  39.    int field_1;
  40.    // $FF: renamed from: k int
  41.    int field_2;
  42.    int countForOpenFile;
  43.    int countForOpenFileSave;
  44.    FileDialog newFile;
  45.    String pathToFile;
  46.    String file;
  47.    BufferedReader openFile;
  48.    String[] artBuffer;
  49.    String[][] layerBuffer;
  50.    TextArea fileBuffer = new TextArea();
  51.    List layers = new List();
  52.    MenuBar menuBar1 = new MenuBar();
  53.    Menu menuFile = new Menu();
  54.    MenuItem menuFileOpen = new MenuItem();
  55.    MenuItem menuFileWriteOut = new MenuItem();
  56.    MenuItem menuFileQuit = new MenuItem();
  57.    MenuItem menuFileRefreshArt = new MenuItem();
  58.    MenuItem menuFileReplaceCharacters = new MenuItem();
  59.    Menu menuLayers = new Menu();
  60.    MenuItem menuLayersAddLayer = new MenuItem();
  61.    MenuItem menuLayersRemoveLayer = new MenuItem();
  62.    MenuItem menuLayersRedrawLayers = new MenuItem();
  63.    Menu menumirror = new Menu();
  64.    MenuItem menumirrorSideWays = new MenuItem();
  65.    MenuItem menumirrorFlipVerticle = new MenuItem();
  66.    Menu menuLineTools = new Menu();
  67.    MenuItem menuLineToolsVerticleLine = new MenuItem();
  68.    MenuItem menuLineToolsHorizantalLine = new MenuItem();
  69.    private boolean mShown = false;
  70.  
  71.    public void initComponents() throws Exception {
  72.       this.fileBuffer.setLocation(new Point(60, 70));
  73.       this.fileBuffer.setVisible(true);
  74.       this.fileBuffer.setSize(new Dimension(480, 360));
  75.       this.layers.setLocation(new Point(570, 270));
  76.       this.layers.setVisible(true);
  77.       this.layers.setSize(new Dimension(130, 160));
  78.       this.menuBar1.add(this.menuFile);
  79.       this.menuBar1.add(this.menuLayers);
  80.       this.menuBar1.add(this.menumirror);
  81.       this.menuBar1.add(this.menuLineTools);
  82.       this.menuFile.setLabel("File");
  83.       this.menuFile.add(this.menuFileOpen);
  84.       this.menuFile.add(this.menuFileWriteOut);
  85.       this.menuFile.add(this.menuFileQuit);
  86.       this.menuFile.add(this.menuFileRefreshArt);
  87.       this.menuFile.add(this.menuFileReplaceCharacters);
  88.       this.menuFileOpen.setLabel("Open");
  89.       this.menuFileWriteOut.setLabel("Write Out");
  90.       this.menuFileQuit.setLabel("Quit");
  91.       this.menuFileRefreshArt.setLabel("Refresh Art");
  92.       this.menuFileReplaceCharacters.setLabel("Replace Characters");
  93.       this.menuLayers.setLabel("Layers");
  94.       this.menuLayers.add(this.menuLayersAddLayer);
  95.       this.menuLayers.add(this.menuLayersRemoveLayer);
  96.       this.menuLayers.add(this.menuLayersRedrawLayers);
  97.       this.menuLayersAddLayer.setLabel("Add Layer");
  98.       this.menuLayersRemoveLayer.setLabel("Remove Layer");
  99.       this.menuLayersRedrawLayers.setLabel("Redraw Layers");
  100.       this.menumirror.setLabel("mirror");
  101.       this.menumirror.add(this.menumirrorSideWays);
  102.       this.menumirror.add(this.menumirrorFlipVerticle);
  103.       this.menumirrorSideWays.setLabel("invert");
  104.       this.menumirrorFlipVerticle.setLabel("Flip Characters Verticle");
  105.       this.menuLineTools.setLabel("Line Tools");
  106.       this.menuLineTools.add(this.menuLineToolsVerticleLine);
  107.       this.menuLineTools.add(this.menuLineToolsHorizantalLine);
  108.       this.menuLineToolsVerticleLine.setLabel("Verticle Line");
  109.       this.menuLineToolsHorizantalLine.setLabel("Horizantal Line");
  110.       ((Component)this).setLocation(new Point(5, 40));
  111.       ((Frame)this).setTitle("asciiShop.mainFrame");
  112.       ((Container)this).setLayout((LayoutManager)null);
  113.       ((Frame)this).setMenuBar(this.menuBar1);
  114.       ((Component)this).setSize(new Dimension(736, 520));
  115.       ((Container)this).add(this.fileBuffer);
  116.       ((Container)this).add(this.layers);
  117.       this.fileBuffer.addTextListener(new 1(this));
  118.       this.layers.addItemListener(new 2(this));
  119.       this.menuFileOpen.addActionListener(new 3(this));
  120.       this.menuFileWriteOut.addActionListener(new 4(this));
  121.       this.menuFileRefreshArt.addActionListener(new 5(this));
  122.       this.menuFileReplaceCharacters.addActionListener(new 6(this));
  123.       this.menuLayersAddLayer.addActionListener(new 7(this));
  124.       this.menumirrorSideWays.addActionListener(new 8(this));
  125.       this.menumirrorFlipVerticle.addActionListener(new 9(this));
  126.       this.menuLineToolsVerticleLine.addActionListener(new 10(this));
  127.       ((Window)this).addWindowListener(new 11(this));
  128.    }
  129.  
  130.    public void addNotify() {
  131.       super.addNotify();
  132.       if (!this.mShown) {
  133.          Insets var1 = ((Container)this).getInsets();
  134.          Component[] var2 = ((Container)this).getComponents();
  135.  
  136.          for(int var3 = 0; var3 < var2.length; ++var3) {
  137.             Point var4 = var2[var3].getLocation();
  138.             var4.move(var4.x, var4.y + var1.top);
  139.             var2[var3].setLocation(var4);
  140.          }
  141.  
  142.          this.mShown = true;
  143.       }
  144.    }
  145.  
  146.    void thisWindowClosing(WindowEvent var1) {
  147.       ((Component)this).setVisible(false);
  148.       ((Frame)this).dispose();
  149.       System.exit(0);
  150.    }
  151.  
  152.    public void list1ItemStateChanged(ItemEvent var1) {
  153.    }
  154.  
  155.    public void layersItemStateChanged(ItemEvent var1) {
  156.    }
  157.  
  158.    public void fileBufferTextValueChanged(TextEvent var1) {
  159.    }
  160.  
  161.    public void menuFileOpenActionPerformed(ActionEvent var1) {
  162.       this.bigString = new String("");
  163.       this.countForOpenFile = 0;
  164.       this.newFile = new FileDialog(this, "Open File", 0);
  165.       this.newFile.setVisible(true);
  166.       this.pathToFile = this.newFile.getDirectory();
  167.       this.file = this.newFile.getFile();
  168.       this.artBuffer = new String[200];
  169.  
  170.       try {
  171.          System.out.println(this.pathToFile + this.file);
  172.          this.openFile = new BufferedReader(new FileReader(this.pathToFile + this.file));
  173.       } catch (FileNotFoundException var2) {
  174.          System.out.println("The file could not be found... DAMN MICROSOFT!!!");
  175.       }
  176.  
  177.       try {
  178.          while(!(this.artBuffer[this.countForOpenFile] = this.openFile.readLine()).equals("***end***")) {
  179.             ++this.countForOpenFile;
  180.          }
  181.       } catch (IOException var3) {
  182.          System.out.println("HOW THE HELL DiD YOU GET THIS ERROR!?");
  183.       }
  184.  
  185.       System.out.println("How many lines in the art: " + this.countForOpenFile);
  186.  
  187.       for(this.field_0 = 0; this.field_0 < this.countForOpenFile; ++this.field_0) {
  188.          this.bigString = this.bigString + this.artBuffer[this.field_0] + "\n";
  189.       }
  190.  
  191.       this.fileBuffer.setText(this.bigString);
  192.       this.countForOpenFileSave = this.countForOpenFile;
  193.    }
  194.  
  195.    public void menuFileWriteOutActionPerformed(ActionEvent var1) {
  196.       this.newFile = new FileDialog(this, "Save File", 1);
  197.       this.newFile.setVisible(true);
  198.       this.pathToFile = this.newFile.getDirectory();
  199.       this.file = this.newFile.getFile();
  200.  
  201.       try {
  202.          this.writeToFile = new PrintWriter(new FileWriter(this.pathToFile + this.file), true);
  203.          System.out.println("Wrote to file: " + this.pathToFile + this.file);
  204.       } catch (IOException var2) {
  205.          System.out.println("GODDAMN HOW THE HELL DID YOU MANAGE TO GET THIS ERROR!?");
  206.       }
  207.  
  208.       this.bigString = this.fileBuffer.getText();
  209.       this.writeToFile.println(this.bigString + "\n***end***");
  210.       System.out.println("Wrote out to file: " + this.pathToFile + this.file + "\n" + this.bigString + "***end***");
  211.    }
  212.  
  213.    public void menuLayersAddLayerActionPerformed(ActionEvent var1) {
  214.       String[][] var2 = this.layerBuffer;
  215.       this.layerBuffer = new String[this.globalCount + 1][200];
  216.  
  217.       for(int var3 = 0; var3 < this.globalCount; ++var3) {
  218.          this.layerBuffer[var3] = var2[var3];
  219.       }
  220.  
  221.       this.countForOpenFile = 0;
  222.       this.newFile = new FileDialog(this, "Add Layer", 0);
  223.       this.newFile.setVisible(true);
  224.       this.pathToFile = this.newFile.getDirectory();
  225.       this.file = this.newFile.getFile();
  226.       this.layerBuffer[this.globalCount] = new String[200];
  227.       System.out.println("Trying to apply layer: " + this.pathToFile + this.file);
  228.  
  229.       try {
  230.          this.openFile = new BufferedReader(new FileReader(this.pathToFile + this.file));
  231.       } catch (IOException var4) {
  232.          System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? - 3");
  233.       }
  234.  
  235.       try {
  236.          while(!(this.layerBuffer[this.globalCount][this.countForOpenFile] = this.openFile.readLine()).equals("***end***")) {
  237.             ++this.countForOpenFile;
  238.          }
  239.       } catch (IOException var5) {
  240.          System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? -2");
  241.       }
  242.  
  243.       this.length1 = this.artBuffer[0].length();
  244.       this.length2 = this.layerBuffer[this.globalCount][0].length();
  245.       if (this.length1 < this.length2) {
  246.          this.useLength = this.length2;
  247.       } else {
  248.          this.useLength = this.length1;
  249.       }
  250.  
  251.       this.artBuffer2 = new char[200][200];
  252.  
  253.       for(this.field_0 = 0; this.field_0 < this.countForOpenFileSave; ++this.field_0) {
  254.          for(this.field_2 = 0; this.field_2 < this.useLength; ++this.field_2) {
  255.             this.artBuffer2[this.field_0][this.field_2] = this.artBuffer[this.field_0].charAt(this.field_2);
  256.          }
  257.  
  258.          for(this.field_1 = 0; this.field_1 < this.useLength; ++this.field_1) {
  259.             if (this.layerBuffer[this.field_0][this.field_1].charAt(this.field_1) != ' ') {
  260.                this.artBuffer2[this.field_0][this.field_1] = this.layerBuffer[this.field_0][this.field_1].charAt(this.field_1);
  261.             } else {
  262.                this.artBuffer2[this.field_0][this.field_1] = ' ';
  263.             }
  264.          }
  265.       }
  266.  
  267.       for(this.field_0 = 0; this.field_0 < this.countForOpenFileSave; ++this.field_0) {
  268.          for(this.field_2 = 0; this.field_2 < this.useLength; ++this.field_2) {
  269.             System.out.println(this.artBuffer2[this.field_0][this.field_2]);
  270.          }
  271.       }
  272.  
  273.       for(this.field_0 = 0; this.field_0 < this.countForOpenFileSave; ++this.field_0) {
  274.          System.out.println(this.artBuffer[this.field_0]);
  275.       }
  276.  
  277.       ++this.globalCount;
  278.    }
  279.  
  280.    public void menumirrorSideWaysActionPerformed(ActionEvent var1) {
  281.       asciiLibs var2 = new asciiLibs(this.artBuffer);
  282.       var2.invert(this.countForOpenFile);
  283.       this.refresh();
  284.    }
  285.  
  286.    public void menuFileRefreshArtActionPerformed(ActionEvent var1) {
  287.       this.bigString = "";
  288.  
  289.       for(this.field_0 = 0; this.field_0 < this.countForOpenFile; ++this.field_0) {
  290.          this.bigString = this.bigString + this.artBuffer[this.field_0] + "\n";
  291.       }
  292.  
  293.       this.fileBuffer.setText(this.bigString);
  294.    }
  295.  
  296.    public void refresh() {
  297.       this.bigString = "";
  298.  
  299.       for(this.field_0 = 0; this.field_0 < this.countForOpenFile; ++this.field_0) {
  300.          this.bigString = this.bigString + this.artBuffer[this.field_0] + "\n";
  301.       }
  302.  
  303.       this.fileBuffer.setText(this.bigString);
  304.    }
  305.  
  306.    public void menumirrorFlipVerticleActionPerformed(ActionEvent var1) {
  307.       asciiLibs var2 = new asciiLibs(this.artBuffer);
  308.       var2.invertVert(this.countForOpenFile);
  309.       this.refresh();
  310.    }
  311.  
  312.    public void menuLineToolsVerticleLineActionPerformed(ActionEvent var1) {
  313.       asciiLibs var2 = new asciiLibs(this.artBuffer);
  314.       var2.horizontalLine(this.countForOpenFile);
  315.       this.refresh();
  316.    }
  317.  
  318.    public void menuFileReplaceCharactersActionPerformed(ActionEvent var1) {
  319.       try {
  320.          asciiLibs var2 = new asciiLibs(this.artBuffer);
  321.          var2.replaceChar(this.countForOpenFileSave);
  322.          this.refresh();
  323.       } catch (IOException var3) {
  324.          System.out.println("Bad stuff has occurred -1");
  325.       }
  326.  
  327.    }
  328. }
  329.